program jjj;

{$APPTYPE CONSOLE}

function subStr(S: string; Start, Count: Integer): String;
var
  i: Integer;
begin
  Result := '';
  for i := Start to Start + Count - 1 do
    Result := Result + S[i];
end;

function isPossible(S, R: String): Integer;
var
  i, r2: Integer;
begin
  if R = '' then begin
    Result := 0;
    Exit;
  end;
  if Length(R) = 1 then begin
    for i := 1 to Length(S) do
      if S[i] = R[1] then begin
        Result := i;
        Break;
      end;
    r2 := -1;
    for i := Length(S) downto 1 do
      if S[i] = R[1] then begin
        r2 := Length(S) - i;
        Break;
      end;
    if (r2 > -1) and (r2 < Result) then
      Result := r2;

    Result := False;
    Exit;
  end;
  Result := False;
  for i := 1 to Length(S) do
    if S[i] = R[1] then begin
      Result := isPossible(subStr(S, i+1, Length(S)-i), subStr(R, 2, Length(R) - 1);
      Break;
    end;
  end;
  if Result then
    Exit;
  for i := Length(S) downto 1 do
    if S[i] = R[1] then begin
      Result := isPossible(subStr(S, 1, i), subStr(R, 2, Length(R) - 1);
      Break;
    end;
  end;
end;

var
  S, R: String;
  k: Integer;
begin
  readln(S);
  readln(R);
  k := 0;
  if isPossible(S, R) then

  for i := 1 to length(R) do begin
    if length(S) = 0 then begin
      writeln(-1);
      Exit;
    end;
    for j := 1 to length(s) do
      if s[j] = R[i] then begin
        Inc(k);
      end;


  end;

    read(a[i]);
  for i := 1 to n do
    read(b[i]);
  for i := 1 to n do
    s := s - abs(a[i]-b[i]);
  writeln(s:0:0);
end.
